/*
 * Powered By XY
 * Since 2020
 */

package com.xy.biz.ts.manager.impl;

import java.util.Collection;
import java.util.List;

import com.xy.biz.ts.dao.TrainFlowHandleDao;
import com.xy.biz.ts.domain.bo.TrainFlowHandleBO;
import com.xy.biz.ts.domain.converter.TrainFlowHandleConverter;
import com.xy.biz.ts.domain.po.TrainFlowHandlePO;
import com.xy.biz.ts.domain.po.TrainSumPO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xy.biz.ts.domain.bo.TrainSumBO;
import com.xy.biz.ts.domain.query.TrainSumQuery;
import com.xy.biz.ts.domain.converter.TrainSumConverter;
import com.xy.biz.ts.manager.TrainSumManager;
import com.xy.biz.ts.dao.TrainSumDao;
import org.springframework.util.CollectionUtils;

/**
 *
 *
 * @author zgy
 * @date 2021-7-29
 */
@Service
public class TrainSumManagerImpl implements TrainSumManager {

    @Autowired
    private TrainSumDao trainSumDao;
    @Autowired
    private TrainFlowHandleDao trainFlowHandleDao;

    @Override
    public TrainSumPO saveTrainSum(TrainSumBO trainSumBO) {
        TrainSumPO trainSumPO = TrainSumConverter.toPO(trainSumBO);
        int row = trainSumDao.saveTrainSum(trainSumPO);
        if (row > 0) {
            List<TrainFlowHandleBO> trainFlowHandleBOList = trainSumBO.getTrainFlowHandleBOList();
            if(!CollectionUtils.isEmpty(trainFlowHandleBOList)){
                List<TrainFlowHandlePO> trainFlowHandlePOS = TrainFlowHandleConverter.toPO(trainFlowHandleBOList);
                trainFlowHandleDao.saveAllTrainFlowHandle(trainFlowHandlePOS);
            }
        }
        return trainSumPO;
    }

    @Override
    public int saveAllTrainSum(Collection<TrainSumBO> collection) {
        return trainSumDao.saveAllTrainSum(TrainSumConverter.toPO(collection));
    }

    @Override
    public int updateTrainSum(TrainSumBO trainSumBO) {
        return trainSumDao.updateTrainSum(TrainSumConverter.toPO(trainSumBO));
    }

    @Override
    public int deleteTrainSum(Long trainSumId) {
        return trainSumDao.deleteTrainSum(trainSumId);
    }

    @Override
    public TrainSumBO getTrainSum(Long trainSumId) {
        return TrainSumConverter.fromPO(trainSumDao.getTrainSum(trainSumId));
    }

    @Override
    public List<TrainSumBO> listTrainSumById(Collection<Long> collection) {
        return TrainSumConverter.fromPO(trainSumDao.listTrainSumById(collection));
    }

    @Override
    public List<TrainSumBO> listTrainSum(TrainSumQuery query) {
        return TrainSumConverter.fromPO(trainSumDao.listTrainSum(query));
    }

    @Override
    public int countTrainSum(TrainSumQuery query) {
        return trainSumDao.countTrainSum(query);
    }

}
